# 格式转换
from configparser import ConfigParser
import json
filename = 'test.ini'
jsonname = 'mysql.json'

cfg = ConfigParser()
cfg.read(filename)

dest = {}

for section in cfg.sections():
    print(section, cfg.items(section)) # 带缺省值
    dest[section] = dict(cfg.items(section))

with open(jsonname, 'w') as f:
    json.dump(dest, f)


print(json.dumps(cfg._sections)) # 不带缺省值

